feat(config): generic resource detector plugin loading for declarative config#5129
Open
MikeGoldsmith wants to merge 6 commits intoopen-telemetry:mainfrom
Open
Conversation
ExperimentalResourceDetector is changed from @DataClass to TypeAlias = dict[str, Any] in models.py, preserving unknown detector names as dict keys through the config pipeline. _run_detectors() now iterates the dict's key-value pairs directly via _RESOURCE_DETECTOR_REGISTRY. Known names (service, host, process) are bootstrapped directly from the SDK. Unknown names — including container and custom plugin detectors — are loaded via the opentelemetry_resource_detector entry point group, matching the spec's PluginComponentProvider mechanism. The container detector behavior changes from warning-when-missing to raising ConfigurationError, consistent with the fail-fast approach agreed on in the issue discussion. Assisted-by: Claude Opus 4.6
22 tasks
_run_detectors() now iterates detector config dicts directly via _RESOURCE_DETECTOR_REGISTRY. Known names (service, host, process) are bootstrapped directly from the SDK. Unknown names — including container and custom plugin detectors — are loaded via the opentelemetry_resource_detector entry point group, matching the spec's PluginComponentProvider mechanism. The generated models are unchanged. Python dataclasses don't enforce field types at runtime, so the detectors list naturally accepts raw dicts (from the YAML loader) alongside typed ExperimentalResourceDetector instances. This preserves unknown plugin names as dict keys without diverging from codegen. The container detector behavior changes from warning-when-missing to raising ConfigurationError, consistent with the fail-fast approach agreed on in the issue discussion. Assisted-by: Claude Opus 4.6
Use typed ExperimentalResourceDetector with additional_properties from the @_additional_properties decorator instead of raw dict iteration. Known schema fields (service, host, process) are checked via _RESOURCE_DETECTOR_REGISTRY. Known fields not in the registry (e.g. container) and unknown plugin names from additional_properties are loaded via entry points. Assisted-by: Claude Opus 4.6
| attrs: dict[str, object] = { | ||
| SERVICE_INSTANCE_ID: str(uuid.uuid4()), | ||
| } | ||
| service_name = os.environ.get(OTEL_SERVICE_NAME) |
Contributor
There was a problem hiding this comment.
nit: use the walrus operator to save a line ?
if service_name := os.environ.get():
| return result.merge(config_resource) | ||
|
|
||
|
|
||
| def _detect_service(_config) -> dict[str, object]: |
Contributor
There was a problem hiding this comment.
the argument to this function is not used ?
| continue | ||
| if name.name in _RESOURCE_DETECTOR_REGISTRY: | ||
| detected_attrs.update( | ||
| _RESOURCE_DETECTOR_REGISTRY[name.name](value) |
Contributor
There was a problem hiding this comment.
Do we just discard value ? It seems we ignore it in all the functions in _RESOURCE_DETECTOR_REGISTRY
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Extends resource detector support in declarative file configuration to handle custom (plugin) detectors, matching the spec's PluginComponentProvider mechanism.
Depends on #5131 (
additional_propertiessupport for generated models).Solution
_run_detectors()iterates the typedExperimentalResourceDetectordataclass fields andadditional_properties:service,host,process) are bootstrapped directly from the SDK via_RESOURCE_DETECTOR_REGISTRYcontainerfrom contrib) are loaded viaload_entry_point("opentelemetry_resource_detector", name)additional_propertiesby the@_additional_propertiesdecorator are also loaded via entry pointsBehavior change
The
containerdetector previously logged a warning when the contrib package was not installed. It now raisesConfigurationError, consistent with the fail-fast approach for declarative config (as discussed in the issue).Custom detector example
Closes #5053